/**
 * 分类书籍
 * @author Qasim <15750783791@163.com>
 * @version 2016/10/31
 */
document.addEventListener('plusready' ,ready , false);

var self = ''
function ready(){
	self = plus.webview.currentWebview();
	$('.keyword').text(self.keyword)
	$.each(self.res, function(k ,v) {
		var html  = '<div class="list-p" data-id="'+v.id+'" data-price="'+v.price+'"><ul class="mui-table-view">';
				html += '<li class="mui-table-view-cell mui-media"><a href="javascript:;">';
				html += '<img class="mui-media-object mui-pull-left" src="'+getImgUrl(v.litpic , "../public/img/book.jpg")+'">';
				html += '<div class="mui-media-body"><span class="mui-h5 back"><span class="book_name">'+v.book_name+'</span>';
				if(v.tid == 37){
					html += '<i class="mui-icon iconfont mui-red">&#xe6e4;</i>';
				}else if(v.trait && v.trait.indexOf(',2,') >= 0){ 
					html += '<i class="mui-icon iconfont mui-red">&#xe6e3;</i>';
				}
				html += '</span><p class="mui-h6 detail">'+v.description+'</p>'; 
				html += '<p class="autor"><span class="mui-h6 back">'+v.author+'</span>';
				html += '</div></a></li></ul></div>';
		$('.lists').append(html); 
		$('.list-p').unbind();
	    $('.list-p').on('click' , function(){ 
	    	bookDetails($(this).attr('data-id') , $(this).attr('data-price'))
	    });
	});
	
//	loadMore();
}


/**
 * 分页加载数据
 * @param {Int} page [开始页]
 */
function loadMore(page , isEnable){ 
	$.ajax({   
		type:"post",  
		url:apiRoot + "/Home/Article/searchData/",
		data:{
			page : page,
			keywords : self.keyword
		},
		beforeSend:function(){
			plus.nativeUI.showWaiting('加载中...');
		},
		complete:function(){
			plus.nativeUI.closeWaiting();
		},
		dataType:'json', 
 		success : function(data){ 
			if(data != ''){
				$.each(data, function(k ,v) {
					var html  = '<div class="list-p" data-id="'+v.id+'" data-price="'+v.price+'"><ul class="mui-table-view">';
						html += '<li class="mui-table-view-cell mui-media"><a href="javascript:;">';
						html += '<img class="mui-media-object mui-pull-left" src="'+getImgUrl(v.litpic , "../public/img/book.jpg")+'">';
						html += '<div class="mui-media-body"><span class="mui-h5 back"><span class="book_name">'+v.book_name+'</span>';
						if(v.tid == 37){
							html += '<i class="mui-icon iconfont mui-red">&#xe6e4;</i>';
						}else if(v.trait && v.trait.indexOf(',2,') >= 0){ 
							html += '<i class="mui-icon iconfont mui-red">&#xe6e3;</i>';
						}
						html += '</span><p class="mui-h6 detail">'+v.description+'</p>'; 
						html += '<p class="autor"><span class="mui-h6 back">'+v.author+'</span>';
						html += '</div></a></li></ul></div>';
					$('.lists').append(html);  
					$('.list-p').unbind(); 
				    $('.list-p').on('click' , function(){ 
				    	bookDetails($(this).attr('data-id') , $(this).attr('data-price'))
				    });
				});  
				if(isEnable)isEnable.endPullUpToRefresh(false); 
			}else{ 
				toast('没有更多的数据了');
				if(isEnable)isEnable.endPullUpToRefresh(true); 
			}
		},
		error : function(e){
			errorPrompt(e);
		}
	});
}
